const express = require('express')
const app = express()
//使用cors解决跨域
const cors = require('cors')
app.use(cors())
//post请求获取数据,让数据在body里面
bodyParser = require('body-parser')
app.use(bodyParser.urlencoded({ extended: false }))
app.use(bodyParser.json())




//全局中间件
app.use((req, res, next) => {
    next();
})


//一级路由
app.use("/admin",require("./Router"))

//错误中间件
app.use((err, req, res, next) => {
    switch (err) {
        case 301:
            res.rend({ code: 301, msg: "token 校验失败" })
            break;
        case 302:
            res.rend({code:302,msg:"账号密码错误"})
            break;
        case 303:
            res.rend({code:303,msg:"验证码错误"})
            break;
        default:
            res.rend({code:404,msg:"未知错误"})
    }
})

//开方静态资源
app.use(express.static('public'))
app.listen(8080);